package main

import (
	"context"
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	"mrshen_xxljob_demo/internal/config"
	"mrshen_xxljob_demo/internal/register"
	"mrshen_xxljob_demo/internal/svc"
	"os"

	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/rest"
)

var configFile = flag.String("f", "etc/application.yaml", "the config file")

func main() {
	flag.Parse()

	var c config.Config
	conf.MustLoad(*configFile, &c)

	server := rest.MustNewServer(c.RestConf)
	defer server.Stop()

	svcCtx := svc.NewServiceContext(c)
	ctx := context.Background()

	// 注册xxl-job信息
	err := register.StartRocketConsumer(ctx, svcCtx, c)
	if err != nil {
		logx.WithContext(ctx).Errorf("!!!xxl job start err !!! run err:%+v", err)
		os.Exit(1)
	}

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()
}
